package leetcode.editor.cn.q1_300.q100;

import java.util.ArrayList;
import java.util.List;

/**
 * @author qidi
 * @date 2022-01-07 15:36:19
 */
class Q0119_PascalsTriangleIi {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<Integer> pre = new ArrayList<>();
            pre.add(1);
            if (rowIndex == 0) return pre;

            List<Integer> cur = new ArrayList<>();

            for (int size = 2; size <= rowIndex + 1; size++) {
                for (int i = 0; i < size; i++) {
                    if (size - 1 == i || i == 0) {
                        cur.add(1);
                    } else {
                        cur.add(pre.get(i - 1) + pre.get(i));
                    }
                }
                pre.clear();
                pre.addAll(cur);
                cur.clear();
            }
            return pre;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0119_PascalsTriangleIi().new Solution();
        for (int i = 1; i <= 6; i++) {
            System.out.println(solution.getRow(i));
        }
    }
}